﻿using System.Web.Mvc;

namespace HashFoo.Rest.Server
{
    /// <summary>
    /// Implementation of a <see cref="IServiceHandler{TRequest}"/> as an <see cref="Controller"/>.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class ResourceController<T> : ResourceController, IServiceHandler<T>
    {
        /// <summary>
        /// Handles the service request.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public abstract ResourceActionResult Handle(T request);
    }

    /// <summary>
    /// Adds resource helper functions to a <see cref="Controller"/>.
    /// </summary>
    public abstract class ResourceController : Controller
    {
        /// <summary>
        /// Returns an emptry <see cref="ResourceActionResult"/>
        /// </summary>
        /// <returns></returns>
        protected ResourceActionResult EmptyResource()
        {
            return Resource<object>(null);
        }

        /// <summary>
        /// Returns a <see cref="ResourceActionResult"/> with the resoure set to <paramref name="result"/>.
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        protected ResourceActionResult Resource<T>(T result)
        {
            return new ResourceActionResult(result);
        }
    }
}